/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is Forte for Java, Community Edition. The Initial * Developer of the Original Code is Sun Microsystems, Inc. Portions * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.web.wizards.beanjsp.ui; import org.netbeans.modules.web.wizards.beanjsp.model.*; import org.netbeans.modules.web.wizards.wizardfw.*; import org.netbeans.modules.web.wizards.beanjsp.ide.netbeans.*; import org.netbeans.modules.web.util.*; import org.netbeans.modules.web.wizards.beanjsp.util.*; import org.openide.util.*; import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; import javax.swing.event.*; public class JSPBizMethodsPanel extends StandardWizardPanel { public JSPBizMethodsPanel() { this(JSPPage.INPUT_PAGE); } public JSPBizMethodsPanel(int pageType) { super(); this.pageType = pageType; initComponents (); addSelectionListeners(); addDoubleClickListeners(); } /*public HelpCtx getHelp () { return new HelpCtx (JSPBizMethodsPanel.class); }*/ /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the FormEditor. */ private void initComponents () {//GEN-BEGIN:initComponents java.util.ResourceBundle resBundle = NbBundle.getBundle(JSPPageWizard.i18nBundle); //// create components this.setTopMessage(resBundle.getString("JBW_BizMethodsMsg")); // NOI18N beanMethodsLabel = new JLabel(resBundle.getString("JBW_AvailableBeansMethodsListTitle")); // NOI18N beanMethodsList = new JList(); beanMethodsSPane = new JScrollPane(beanMethodsList); useBeanMethodsLabel = new JLabel(resBundle.getString("JBW_UseBeansMethodsListTitle")); // NOI18N useBeanMethodsList = new JList(); useBeanMethodsSPane = new JScrollPane(useBeanMethodsList); beanMethodsSPane.setPreferredSize (new java.awt.Dimension(200, 200)); useBeanMethodsSPane.setPreferredSize (new java.awt.Dimension(200, 200)); buttonsPanel = new javax.swing.JPanel(); addButton = new javax.swing.JButton (); addButton.setText (resBundle.getString("JBW_AddButton")); // NOI18N addButton.setMinimumSize (new java.awt.Dimension(73, 15)); addButton.setMaximumSize (new java.awt.Dimension(100, 27)); removeButton = new javax.swing.JButton (); removeButton.setText (resBundle.getString("JBW_RemoveButton")); // NOI18N removeButton.setMinimumSize (new java.awt.Dimension(73, 15)); removeButton.setMaximumSize (new java.awt.Dimension(100, 27)); addAllButton = new javax.swing.JButton (); addAllButton.setText (resBundle.getString("JBW_AddAllButton")); // NOI18N addAllButton.setMinimumSize (new java.awt.Dimension(73, 15)); addAllButton.setMaximumSize (new java.awt.Dimension(100, 27)); removeAllButton = new javax.swing.JButton (); removeAllButton.setText (resBundle.getString("JBW_RemoveAllButton")); // NOI18N removeAllButton.setMinimumSize (new java.awt.Dimension(73, 15)); removeAllButton.setMaximumSize (new java.awt.Dimension(100, 27)); moveUpButton = new javax.swing.JButton (); moveUpButton.setText (resBundle.getString("JBW_MoveUpButton")); // NOI18N moveUpButton.setMinimumSize (new java.awt.Dimension(73, 15)); moveUpButton.setMaximumSize (new java.awt.Dimension(100, 27)); moveDownButton = new javax.swing.JButton (); moveDownButton.setText (resBundle.getString("JBW_MoveDownButton")); // NOI18N moveDownButton.setMinimumSize (new java.awt.Dimension(73, 15)); moveDownButton.setMaximumSize (new java.awt.Dimension(100, 27)); //// layout and add components arrangeComponents(); //// create and add listeners beanMethodsModel = JSPPageWizard.simpleJSPPage.getAvailableBeanMethodsModel(); beanMethodsList.setModel(beanMethodsModel); useBeanMethodsModel = JSPPageWizard.simpleJSPPage.getBizMethodsModel(); this.useBeanMethodsList.setModel(useBeanMethodsModel); addAllButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { addAllToUseBeanMethodsList(); } }); removeAllButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { removeAllFromFromUseBeanMethodsList(); } }); addButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { addToUseBeanMethodsList(); } }); removeButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { removeFromUseBeanMethodsList(); } }); moveUpButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { moveUpUseBeanMethod(); } }); moveDownButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent evt) { moveDownUseBeanMethod(); } }); }//GEN-END:initComponents //// layout components in private void arrangeComponents() { createButtonPanelComponents(); arrangeCompsWithGridBag(); } private void addGridBagComponent(Container parent, Component comp, int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, int anchor, int fill, Insets insets, int ipadx, int ipady ) { GridBagConstraints cons = new GridBagConstraints(); cons.gridx = gridx; cons.gridy = gridy; cons.gridwidth = gridwidth; cons.gridheight = gridheight; cons.weightx = weightx; cons.weighty = weighty; cons.anchor = anchor; cons.fill = fill; cons.insets = insets; cons.ipadx = ipadx; cons.ipady = ipady; parent.add(comp,cons); } private void createButtonPanelComponents() { this.buttonsPanel.setLayout(new GridBagLayout()); Component allGap = Box.createVerticalStrut(2); Component moveGap = Box.createVerticalStrut(6); Component remainderGlue = Box.createGlue(); addGridBagComponent(this.buttonsPanel,addButton, 0,0,1,1, 100,00, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2,2,2,2),5,5 ); addGridBagComponent(this.buttonsPanel,removeButton, 0,1,1,1, 100,0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2,2,2,2),5,5 ); addGridBagComponent(this.buttonsPanel,allGap, 0,2,1,1, 100,0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2,2,2,2),5,5 ); addGridBagComponent(this.buttonsPanel,addAllButton, 0,3,1,1, 100,00, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2,2,2,2),5,5 ); addGridBagComponent(this.buttonsPanel,removeAllButton, 0,4,1,1, 100,0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2,2,2,2),5,5 ); addGridBagComponent(this.buttonsPanel,moveGap, 0,5,1,1, 100,0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2,2,2,2),5,5 ); addGridBagComponent(this.buttonsPanel,moveUpButton, 0,6,1,1, 100,0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2,2,2,2),5,5 ); addGridBagComponent(this.buttonsPanel,moveDownButton, 0,7,1,1, 100,0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(2,2,2,2),5,5 ); addGridBagComponent(this.buttonsPanel,remainderGlue, 0,8,1,1, 100,100, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(2,2,2,2),5,5 ); } private void arrangeCompsWithGridBag() { this.contentPane.setLayout(new GridBagLayout()); addGridBagComponent(this.contentPane,beanMethodsLabel, 0,0,1,1, 100,0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(2,2,2,2),5,5 ); addGridBagComponent(this.contentPane,useBeanMethodsLabel, 2,0,1,1, 100,0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(2,2,2,2),5,5 ); addGridBagComponent(this.contentPane,beanMethodsSPane, 0,1,1,1, 100,100, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(2,2,2,2),5,5 ); addGridBagComponent(this.contentPane,buttonsPanel, 1,1,1,1, 0,100, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(2,2,2,2),5,5 ); addGridBagComponent(this.contentPane,useBeanMethodsSPane, 2,1,1,1, 100,100, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(2,2,2,2),5,5 ); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel titleLabel; private javax.swing.JScrollPane beanMethodsSPane; private javax.swing.JList beanMethodsList; private javax.swing.JLabel beanMethodsLabel; private javax.swing.JPanel buttonsPanel; private javax.swing.JButton addButton; private javax.swing.JButton removeButton; private javax.swing.JButton addAllButton; private javax.swing.JButton removeAllButton; private javax.swing.JButton moveUpButton; private javax.swing.JButton moveDownButton; private javax.swing.JScrollPane useBeanMethodsSPane; private javax.swing.JList useBeanMethodsList; private javax.swing.JLabel useBeanMethodsLabel; private JSPItemListModel beanMethodsModel; private JSPItemListModel useBeanMethodsModel; private int pageType = JSPPage.INPUT_PAGE; // methods public void addAllToUseBeanMethodsList() { JSPVector addMethods = beanMethodsModel.getItems(); useBeanMethodsModel.addItems(addMethods); beanMethodsModel.removeAll(); setButtonsEnabled(); } public void removeAllFromFromUseBeanMethodsList() { JSPVector removeMethods = useBeanMethodsModel.getItems(); beanMethodsModel.addItems(removeMethods); useBeanMethodsModel.removeAll(); setButtonsEnabled(); } public void addToUseBeanMethodsList() { int[] idx = beanMethodsList.getSelectedIndices(); int count = 0; int oldRows = useBeanMethodsModel.getSize(); if( (idx.length > 0) && (idx[0] >= 0)){ for (int i=0; i<idx.length; i++) { Object obj = beanMethodsModel.remove(idx[i]-count); useBeanMethodsModel.add(obj); count++; } // set selection for useBeanMethods int rows = useBeanMethodsModel.getSize(); useBeanMethodsList.getSelectionModel().setSelectionInterval( oldRows, rows-1); setButtonsEnabled(); } } public void removeFromUseBeanMethodsList() { int[] idx = useBeanMethodsList.getSelectedIndices(); int count = 0; int oldRows = beanMethodsModel.getSize(); if((idx.length > 0) && (idx[0] >= 0)) { for (int i=0; i<idx.length; i++) { Object obj = useBeanMethodsModel.remove(idx[i]-count); beanMethodsModel.add(obj); count++; } // set selection for useBeanMethods int rows = beanMethodsModel.getSize(); beanMethodsList.getSelectionModel().setSelectionInterval( oldRows, rows-1); setButtonsEnabled(); } } public void moveUpUseBeanMethod() { int[] idx = useBeanMethodsList.getSelectedIndices(); if((idx.length > 0) && (idx[0] > 0 )) { for (int i=0; i<idx.length; i++){ useBeanMethodsModel.moveUp(idx[i]); } useBeanMethodsList.getSelectionModel().setSelectionInterval( idx[0]-1, idx[idx.length-1]-1); checkButtons(); } } public void moveDownUseBeanMethod() { int[] idx = useBeanMethodsList.getSelectedIndices(); int rowCount = useBeanMethodsModel.getSize(); if((idx.length >0) && (idx[0] >= 0) && (idx[idx.length-1] < rowCount-1)) { for (int i=idx.length-1; i>=0; i--){ useBeanMethodsModel.moveDown(idx[i]); } useBeanMethodsList.getSelectionModel().setSelectionInterval( idx[0]+1,idx[idx.length-1]+1); checkButtons(); } } public void filterExistingBeanMethods() { Debug.print(new Exception("Implement this method")); // NOI18N } public void setButtonsEnabled(){ if (beanMethodsModel.getSize() > 0){ addAllButton.setEnabled(true); } else { addAllButton.setEnabled(false); } if (useBeanMethodsModel.getSize() > 0){ removeAllButton.setEnabled(true); } else { removeAllButton.setEnabled(false); } checkAddButton(); checkButtons(); } private void checkAddButton(){ if ((beanMethodsModel.getSize() > 0) && (beanMethodsList.getSelectedIndex()>=0)) addButton.setEnabled(true); else addButton.setEnabled(false); } private void checkButtons(){ int rows = useBeanMethodsModel.getSize(); int[] srow = useBeanMethodsList.getSelectedIndices(); if ((rows > 0) && (srow.length >0)){ removeButton.setEnabled(true); } else { removeButton.setEnabled(false); } if ((rows > 1) && (srow.length >0) && (srow[0] > 0)){ moveUpButton.setEnabled(true); } else { moveUpButton.setEnabled(false); } if ((rows > 1) && (srow.length >0) && (srow[srow.length -1] < rows -1)){ moveDownButton.setEnabled(true); } else { moveDownButton.setEnabled(false); } } private void addSelectionListeners(){ beanMethodsList.addListSelectionListener(new ListSelectionListener(){ public void valueChanged(ListSelectionEvent e){ checkAddButton(); } }); useBeanMethodsList.addListSelectionListener( new ListSelectionListener(){ public void valueChanged(ListSelectionEvent e){ checkButtons(); } }); } private void addDoubleClickListeners(){ beanMethodsList.addMouseListener (new java.awt.event.MouseAdapter () { public void mouseClicked (java.awt.event.MouseEvent evt) { beanMethodsListMouseClicked(evt); } }); useBeanMethodsList.addMouseListener (new java.awt.event.MouseAdapter () { public void mouseClicked (java.awt.event.MouseEvent evt) { useBeanMethodsListMouseClicked(evt); } }); } private void beanMethodsListMouseClicked(java.awt.event.MouseEvent evt) { if (evt.getClickCount() == 2) { addToUseBeanMethodsList(); } } private void useBeanMethodsListMouseClicked(java.awt.event.MouseEvent evt) { if (evt.getClickCount() == 2) { removeFromUseBeanMethodsList(); } } public static void main(String[] args) { if(Debug.TEST) { JFrame testFrame = new JFrame("This is Test Frame"); // NOI18N testFrame.getContentPane().add(new JSPBizMethodsPanel(),SwingConstants.CENTER); testFrame.setSize(500,300); testFrame.pack(); testFrame.show(); } } }